package com.ll.gulimall.serach.controller;

import com.ll.common.exception.BizCodeEnume;
import com.ll.common.to.es.SkuEsModel;
import com.ll.common.utils.R;
import com.ll.gulimall.serach.service.SearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 21243
 */
@RequestMapping("/search/save")
@RestController
@Slf4j
public class SearchSaveController {

    @Autowired
    private SearchService searchService;

    /**
     * 商品上架
     *
     * @param skuEsModels
     * @return
     */
    @PostMapping("/productUp")
    public R productUp(@RequestBody List<SkuEsModel> skuEsModels) {
        Boolean b;
        try {
            b = searchService.productUp(skuEsModels);
        } catch (Exception e) {
            log.error("ElastSearch商品上架错误{}", e);
            return R.error(BizCodeEnume.PORUDUCT_UP_EXECEPTION.getCode(), BizCodeEnume.PORUDUCT_UP_EXECEPTION.getMsg());
        }

        System.out.println(b);
        if (!b) {
            return R.ok();
        } else {
            return R.error(BizCodeEnume.PORUDUCT_UP_EXECEPTION.getCode(), BizCodeEnume.PORUDUCT_UP_EXECEPTION.getMsg());
        }


    }
}
